/*
 * This source code is part of TWaver 4.0
 *
 * Serva Software PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 * Copyright 2002 - 2011 Serva Software. All rights reserved.
 */

package demo.network.chassis.customgrid;

import java.awt.Insets;
import java.awt.Rectangle;

import twaver.Follower;
import twaver.TUIManager;

public class CustomGrid extends Follower{
	
	static{
		TUIManager.registerWithoutImage(CustomGrid.class);
	}
	
	private int rowCount = 1;
	private int columnCount = 1; 
	private Insets insets = new Insets(25, 20, 10, 10);
	
	public CustomGrid(){	
	}

	public CustomGrid(Object id){
		super(id);
	}
	
	public int getColumnCount() {
		return columnCount;
	}

	public void setColumnCount(int columnCount) {
		if(this.columnCount != columnCount){
			int oldValue = this.columnCount;
			this.columnCount = columnCount;
			this.firePropertyChange("columnCount", oldValue, this.columnCount);
		}
	}

	public int getRowCount() {
		return rowCount;
	}

	public void setRowCount(int rowCount) {
		if(this.rowCount != rowCount){
			int oldValue = this.rowCount;
			this.rowCount = rowCount;
			this.firePropertyChange("rowCount", oldValue, this.rowCount);
		}
	}

	public Insets getInsets() {
		return insets;
	}

	public void setInsets(Insets insets) {
		Insets oldValue = this.insets;
		this.insets = insets;
		this.firePropertyChange("insets", oldValue, this.insets);
	}

	public String getUIClassID() {
		return CustomGridUI.class.getName();
	}

	public Rectangle getInnerBounds(){
		Rectangle bounds = this.getBounds();
		bounds.x += insets.left;
		bounds.y += insets.top;
		bounds.width -= insets.left + insets.right;
		bounds.height -= insets.top + insets.bottom;
		return bounds;
	}
	
	public Rectangle getCellRect(int row, int column) {
        Rectangle bounds = this.getInnerBounds();
        double w = bounds.getWidth() / this.getColumnCount();
        double h = bounds.getHeight() / this.getRowCount();
        double x = bounds.x + column * w;
        double y = bounds.y + row * h;
        return new Rectangle((int)x, (int)y, (int)w, (int)h);
	}
}